﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

/// <summary>
///DateTimeEditShow 的摘要说明
/// </summary>
public class DateTimeEditShow:BaseEditShowField
{
	public DateTimeEditShow()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public override IEnumerable<System.Web.UI.Control> GetThisTypeControl(ConfigColumns cCol, string value, bool isEdit)
    {
        DatePicker ctrl = new DatePicker();
        ctrl.ID = cCol.ColumnName + "_EditShow";
        ctrl.ValidationGroup = "Edit";
        if (!string.IsNullOrEmpty(cCol.EditShowTextBoxWidth))
        {
            ctrl.Width = new Unit(cCol.EditShowTextBoxWidth);
        }
        if (isEdit)
        {
            ctrl.Text = value;
        }
        else
        {
            if (!string.IsNullOrEmpty(cCol.AddShowDefaultValue))
            {
                DateTime defaultV = DateTime.Now;
                if (DateTime.TryParse(cCol.AddShowDefaultValue, out defaultV))
                {
                    ctrl.Text = cCol.AddShowDefaultValue;
                }
                else
                {
                    ctrl.Text = DateTime.Now.ToString();
                }
            }
            else
            {
                ctrl.Text = DateTime.Now.ToString();
            }
        }

        yield return ctrl;

        if (cCol.EditShowRequired)
        {
            RequiredFieldValidator requiredV = new RequiredFieldValidator();
            requiredV.ErrorMessage = "*";
            requiredV.SetFocusOnError = true;
            requiredV.ValidationGroup = "Edit";
            requiredV.ControlToValidate = cCol.ColumnName + "_EditShow";
            requiredV.Display = ValidatorDisplay.Dynamic;
            yield return requiredV;
        }

        if (cCol.EditShowRange)
        {
            RangeValidator rangeV = new RangeValidator();
            rangeV.ID = cCol.ColumnName + "_range";
            rangeV.ValidationGroup = "Edit";
            rangeV.MinimumValue = cCol.EditShowRangeMinValue;
            rangeV.MaximumValue = cCol.EditShowRangeMaxValue;
            rangeV.ControlToValidate = cCol.ColumnName + "_EditShow";
            rangeV.ErrorMessage = rangeV.MinimumValue + " - " + rangeV.MaximumValue;
            rangeV.SetFocusOnError = true;
            rangeV.Type = cCol.EditShowRangeType;
            rangeV.Display = ValidatorDisplay.Dynamic;

            yield return rangeV;
        }
        if (cCol.EditShowRegExp)
        {
            RegularExpressionValidator regV = new RegularExpressionValidator();
            regV.ID = cCol.ColumnName + "_regexp";
            regV.ControlToValidate = cCol.ColumnName + "+EditShow";
            regV.SetFocusOnError = true;
            regV.Display = ValidatorDisplay.Dynamic;
            regV.ValidationGroup = "Edit";
            regV.ValidationExpression = cCol.EditShowRegExpText;
            regV.ErrorMessage = cCol.EditShowRegExpErrMessage;

            yield return regV;
        }
    }
}
